export type Channel = { id: number; name: string }

const initState = {
  activeId: 0,
  list: [] as Channel[],
  allList: [] as Channel[],
}

export type ChannelAction =
  | { type: 'channel/saveList'; payload: Channel[] }
  | { type: 'channel/saveAllList'; payload: Channel[] }
  | { type: 'channel/changeActiveId'; payload: number }

export default function channelReducer(
  state = initState,
  action: ChannelAction
) {
  switch (action.type) {
    case 'channel/saveList':
      return { ...state, list: action.payload }
    case 'channel/saveAllList':
      return { ...state, allList: action.payload }
    case 'channel/changeActiveId':
      return { ...state, activeId: action.payload }
    default:
      return state
  }
}
